#include "interface.h"

#include <iostream>
#include <string>
using namespace std;

#include "converter.h"
#include "calc.h"

string Interface::title()
{
	return "GCalc 1.0";
}

void Interface::head()
{
	cout << "Welcome to " + title() + " - Developed by Pedro Silva Moreira - PeJuGe." << endl
	cout << "Access: http://gcoders.wordpress.com" << endl
	<< endl;
}

uint32 Interface::command( string f_str )
{
	if ( f_str == "calc" ) return CALC;
	if ( f_str == "help" ) return HELP;
	if ( f_str == "about" ) return ABOUT;
	if ( f_str == "quit" ) return QUIT;

	return 0;
}

string Interface::name( uint32 f_id )
{
	switch ( f_id )
	{
		case CALC:  return "Calc";
		case HELP:  return "Help";
		case ABOUT: return "About";
		case QUIT:  return "Quit";
	}
	return "";
}

string Interface::commands()
{
	cout << "Commands:" << endl
	     << "[Calc] : Execute calcs." << endl
	     << "[Help] : Knowledge about use." << endl
	     << "[About]: Data of creators and other informations." << endl
	     << "[Quit] : Finish program." << endl;

	cout << "Your choose...: ";
	return Interface::read_lower();
}

string Interface::read()
{
	string f_read;
	getline( cin, f_read );

	return f_read;
}

string Interface::read_lower()
{
	return Converter::string_lower( read() );
}

uint32 Interface::calc()
{
	Calc f_calc = Calc();

	cout << "Write your calc: ";
	string f_read = read();

	if ( command( Converter::string_lower( f_read ) ) != 0 )
	{
		return command( f_read );
	}

	f_calc.execute( f_read );
	cout << endl << "Answer: " << f_calc.value()->get() << endl;

	return 0;
}

void Interface::help()
{
	cout << "Operators: " << endl
	     << "[+] : Sum                 (2+2=4)" << endl
	     << "[-] : Subtraction         (2-2=0)" << endl
	     << "[*] : Multiplication      (2*3=6)" << endl
	     << "[/] : Division            (2/2=1)" << endl
	     << "[^] : Exponentiation      (2^3=8)" << endl
	     << "[r] : Root                (r16=2r16=4, 3r8=2)" << endl
	     << "[!] : Factorial           (3!=6, 5!3=5!/3!=20)" << endl
	     << "[l] : Logarithm           (2l=log2, 4l2=log4 on base 2)" << endl
	     << "[c] : Cossine             (c2=cos2, 2c4=2*cos4)" << endl
	     << "[s] : Sine                (s2=sin2, 2s4=2*sin4)" << endl
	     << "[t] : Tangent             (t2=tan2, 2t4=2*tan4)" << endl
	     << "[m] : Mod                 (3m2=1, moreover operator)" << endl
	     << "[e] : Exponentiaton by 10 (2e3=2*10^3=2000, 2e=20)" << endl
	     << "You can use (...) on your calcs like 2*(3-1)." << endl;
}

void Interface::about()
{
	cout << title() << " has been developed by Pedro Silva Moreira - PeJuGe." << endl
	     << "The objective is help the students of C++ programming and everybody who wanna use it." << endl
	     << endl
	     << "Blog: http://gcoders.wordpress.com" << endl
	     << "April, 2011." << endl;
}

void Interface::quit()
{
	cout << "Thanks for use " + title() + "." << endl;
}
